import Vue from 'vue'

// 导入网络请求包
import axios from 'axios'

// 导入 nprogress 的 js 和 css
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

axios.defaults.baseURL = process.env.VUE_APP_BASE_API
// 在 request 拦截器中展示进度条 NProgress.start()
axios.interceptors.request.use(config => {
  NProgress.start()
  // console.log(config);
  config.headers.Authorization = window.sessionStorage.getItem("token");
  // 在最后必须 return config
  return config;
})
// 在 response 拦截器中隐藏进度条 NProgress.done()
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})

Vue.prototype.$http = axios;

// https://help.aliyun.com/document_detail/31926.html?spm=a2c4g.11186623.2.9.33fb4367Wp71jr#concept-en4-sjy-5db
// 阿里云 OSS 服务端签名后直传
const bucketName = 'objstore'
Vue.prototype.uploadGetSignUrl = 'http://fc.diff.wang/policy?bucket_name=' + bucketName
// Vue.prototype.uploadUrl = 'https://' + bucketName + '.oss-cn-hangzhou.aliyuncs.com'
Vue.prototype.uploadUrl = 'http://' + bucketName + '.oss-cn-hangzhou.aliyuncs.com'